package cn.linjianhui.demo.flink;

import org.apache.flink.streaming.api.functions.source.SourceFunction;

import java.util.Random;

public class RandomDataSource implements SourceFunction<Integer> {
    private volatile boolean isRunning = true;

    @Override
    public void run(SourceContext<Integer> ctx) throws Exception {
        Random rand = new Random();
        while (isRunning) {
            Thread.sleep(1000);
            ctx.collect(rand.nextInt(9999));
        }
    }

    @Override
    public void cancel() {
        isRunning = false;
    }
}
